
//import data
g lngdp=log(currentGDP)
g lnfdi=log(FDI_ABS)


encode country, gen(country1)
xtset country1 year

//descriptive statistics
xtdescribe

//summary table
outreg2 using results, word replace sum(log)

//correlation matrix
xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab, fe vce(cluster country1)
estat vce, corr

//test to see whether fe or re

//1. Sargan-Hansen

xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab, fe vce(cluster country1)
estimates store fixed
xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab, re vce(cluster country1)
estimates store random
xtoverid

//2 Hausman test
xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab, fe
estimates store fixed
xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab, re 
estimates store random
hausman fixed random

//also put Hausman test, mention that I did this too and gave same result,but: Hausman cannot be carried out with clustered (vce) and also because the most important assumption of RE is that entities are randomly chosen (random effects), which is not the case for countries

// is this Sargan-Hansen statistics
// if p-value 0.0031

//1 OLS --> include this, dont interpret (it is there at baseline)
xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab

//2 OLS with year-effect bc. running reg (2)
reg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab i.year
//difference to 3: 3: time is not in regression, 2: time is in regression

//3 FE --> proper (3)
xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab, fe vce(cluster country1)

//4 FE with year-effect (4)
xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab i.year , fe vce(cluster country1)

//summary:
xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab
reg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab i.year
xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab, fe vce(cluster country1)
xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab i.year , fe vce(cluster country1)


//variable labeling:
label variable lnfdi "log FDI"
label variable lngdp "log GDP"
label variable SM "Screening Mechanism"
label variable inflat "Inflation"
label variable RD "Research & Development"
label variable corrupt "Corruption"
label variable educat "Education"
label variable tradeopen "Trade Openness"
label variable polstab "political stability"
label variable unempl "Unemployment Rate"
label variable taxrate "Tax Rate"

//////////////////////////////////////////////////////////////////////////////////////////////////
//what to report:

//normal vs FE (country + time) vs RE
xtreg lnfdi lngdp SM taxrate tradeopen  educat inflat corrupt polstab

xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab i.year , fe vce(cluster country1)

xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab i.year , re vce(cluster country1)

//Hausman test

//Sargans-Hansen test
xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab, fe vce(cluster country1)
estimates store fixed
xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab, re vce(cluster country1)
estimates store random
xtoverid

// robustness check:
//1. split into two sample periods:
drop if year==2016
drop if year==2017
drop if year==2018
drop if year==2019
drop if year==2020

//and
g d2015=0
replace d2015=1 if year<2016
gen d2016=0
replace d2016=1 if year >2015
g interdummy= d2016*SM
sum d2016 d2015
xtreg lnfdi lngdp SM taxrate tradeopen educat inflat corrupt polstab i.year d2016 interdummy , fe vce(cluster country1)

//2. emerging vs developed economies: Simply drop emerging/developing countries and carry out regressions



